﻿@using SmartSiteManagementSystem.Models.User;
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.BodyClass = "easyui-layout";
}

<div id="tbtool" class="gou-toolbar" style="padding:3px;">
     <form method="post" action="/ProjectManage/DayProjectIndex" id="searchForm">
    <span>子计划名称:</span>
    <input id="searchKey" name="searchKey" maxlength="25" style="line-height:26px;border:1px solid #ccc">

              <input id="BeginTime" name="BeginTime" type="text" class="easyui-datebox" style="width:180px;">-<input id="EndTime" name="EndTime" type="text" class="easyui-datebox" style="width:180px;">

    <a href="javascript:;" class="easyui-linkbutton" iconcls="icon-search" onclick="Search();">查找</a>
    <a href="javascript:void(0);" onclick="AddOrEditDayProject(@(ViewBag.projectId),0);" class="easyui-linkbutton" iconcls="icon-add">新增</a>
        </form>
</div>

<table id="grid" data-options="region:'center',border:false" class="easyui-datagrid"
       rownumbers="true" fitcolumns="true" singleselect="true" fit="true" pagesize="50"></table>


<!--分配任务弹出窗口-->
<div id="divAssignProjectOperate" style="display:none">
    <div id="tblog" style="padding:5px;border-width:0;">
       <input type="hidden" id="hidDayProjectId" />
        <div style="text-align:left;margin-top:10px;">
            <font color="red">*</font>分配任务对应人：
            <select  id="combo_selUser" name="combo_selUser" class="easyui-combobox" style="width:150px;">
                
                <option value="-1">请选择任务对应人</option>
                  @foreach (var item in ViewBag.userList as IList<UserInfo>)
                {

                    <option value="@item.UserId"> @(item.ShowName) </option>
                }

            </select>
        </div>
        <div style="text-align:center;margin-top:10px;">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'"
               onclick="javascript: doAssignProjectOperate();" style="width:80px;height:30px">分配</a>
        </div>
    </div>
</div>


@section Script{

    <script type="text/javascript">
        $(function () {
            function formatOper(val, row, index) {
                var rek = "";
                var cor = "";
                var opt = "";
                 if(row.StatusType<10)
                {
                opt = opt + '&nbsp<a href="javascript:void(0);" onclick="AddOrEditDayProject(\'' + row.ProjectId + '\',\'' + row.DayProjectId + '\');">编辑</a>&nbsp|&nbsp;<a href="javascript:void(0);" onclick="deleteDayProject(\'' + row.DayProjectId + '\');">删除</a>&nbsp';
                }
                if(row.StatusType<=5)
                {
                   opt = opt + '&nbsp<a href="javascript:void(0);" onclick="ShowAssignProjectOperate(\'' + row.DayProjectId + '\',\'' + row.UserId + '\');">分配任务</a>';
                }
                 if(row.StatusType==5)
                {
                   opt = opt + '&nbsp<a href="javascript:void(0);" onclick="confirmIssue(\'' + row.DayProjectId + '\',\'' + row.UserId + '\');">下发任务</a>';
                }
                return opt ;
            }
            $('#grid').datagrid({
                url: 'GetDayProjectList?projectId=@(ViewBag.projectId)&searchKey=' + $("#searchKey").val(),
                columns: [[{ field: 'DayProjectId', title: 'Id', width:5 },{ field: 'DayProjectName', title: '子计划名称', width:15 }
        ,{ field: 'DayProjectTypeName', title: '子计划任务类型', width: 15 }
        ,{ field: 'StatusTypeStr', title: '状态', width: 5 },{ field: 'StartTimeStr', title: '开始时间', width: 10},{ field: 'EndTimeStr', title: '结束时间', width: 10 },
        { field: 'UserStr', title: '任务分配', width: 10  },
{ field: 'IssueStr', title: '是否下发', width: 10 },{ field: 'IssueTimeStr', title: '下发时间', width: 10  },{ field: 'CreateTimeStr', title: '创建时间', width: 10 }, { field: '_operate', title: '操作', width: 20, align: 'center', formatter: formatOper}
                ]],
                toolbar: '#tbtool',
                pagination: true
            });
            var pager = $('#grid').datagrid('getPager');	// get the pager of datagrid
            pager.pagination({
                showPageList: true,
                pageSize: 50
            });

        });
        function Search() {    
          
            var StartTime = $("input[name=BeginTime]").val();
            var EndTime = $("input[name=EndTime]").val();

           if (StartTime != undefined && StartTime!=""&&EndTime != undefined && EndTime!="" )
         {
             var dtstartTime = new Date(Date.parse(StartTime));
            var dtendTime = new Date(Date.parse(EndTime));
            if(StartTime>=EndTime)
            {
                utils.MsgShow("消息提示", "请选择正确的时间段!", true);
                return;
            }

        }
            $('#grid').datagrid("load", {
                searchKey: $("#searchKey").val()
            });
        }

        function deleteDayProject(id) {
            var rek = "删除";
            $.messager.confirm(rek, "你确定" + rek + "吗?", function (istrue) {
                if (istrue) {
                    var param = { dayProjectId: id };
                    $.ajax({
                        "type": "Post",
                        "url": "ajaxdeleteDayProject?t=" + new Date().getTime(),
                        "dataType": "json",
                        "data": param,
                        "success": function (data) {
                            if (data.IsSuccess) {
                                $.messager.alert('提示', data.Msg);
                                $("#grid").datagrid("reload");
                            }
                            else
                            {
                                $.messager.alert('提示', data.Msg);
                             }
                        }
                    });
                }
            });
           
        }

       

        function AddOrEditDayProject(projectId,id) {
            window.location.href = "AddOrEditDayProject?projectId="+projectId+"&id=" + id;
        }

      //分配任务 弹出框
    function ShowAssignProjectOperate(dayProjectId,userId) {
        $('#divAssignProjectOperate').css("display", "block");
        $("#hidDayProjectId").val(dayProjectId);
        /*if(userId>0)
        {
           $("[name=combo_selUser]").combobox('setValue',userId);
        }*/
        utils.WindowOpen('divAssignProjectOperate', { title: '分配任务', height: 180, width: 320, closed: true });

    }




 
            //确认收货
    function doAssignProjectOperate()
    {
        var dayProjectId = $("#hidDayProjectId").val();
        var selUserId = $("[name=combo_selUser]").val();
        if ($.trim(selUserId)=="") {
            utils.MsgShow("消息提示", "请选择任务对应人!", true);
            return;
        }
        $.ajax({
            "type": "Post",
            "url": "doAssignProject?t=" + new Date().getTime(),
            "dataType": "json",
            "data": { dayProjectId: dayProjectId, userId: selUserId},
            "success": function (data) {
                if (data.IsSuccess) {
                    utils.MsgShow("消息提示", data.Msg, true);
                    utils.WindowCloss("divAssignProjectOperate");
                    $("#grid").datagrid("reload");
                }
                else {
                    utils.MsgShow("消息提示", data.Msg, true);
                }
            }
        });
    }

    //下发任务
    function confirmIssue(dayProjectId,userId)
    {
        $.messager.confirm('下发任务', '下发任务后将不可修改，请谨慎', function (r) {
            if (r) {
                $.ajax({
                    "type": "Post",
                    "url": "doIssueProject?t=" + new Date().getTime(),
                    "dataType": "json",
                    "data": { dayProjectId: dayProjectId, userId: userId },
                    "success": function (data) {
                if (data.IsSuccess) {
                    utils.MsgShow("消息提示", data.Msg, true);

                    $("#grid").datagrid("reload");
                }
                else {
                    utils.MsgShow("消息提示", data.Msg, true);
                }
                    }
                });
            }
        });
    }

    </script>
}





